package com.yun.zf.app.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yun.zf.app.mapper.SysUserOrderMapper;
import com.yun.zf.app.service.SysUserOrderService;
import com.yun.zf.common.admin.domain.SysUserOrder;
import com.yun.zf.common.app.dto.center.OrderListDto;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 用户订单合同关系表 服务实现类
 * </p>
 *
 * @author cj
 * @since 2021-08-18
 */
@Service
public class SysUserOrderServiceImpl extends ServiceImpl<SysUserOrderMapper, SysUserOrder> implements SysUserOrderService {

    @Override
    public List<OrderListDto> getMyOrder(Long userId) {
        //1、 获取用户订单
        QueryWrapper<SysUserOrder> wrapper = new QueryWrapper<>();
        wrapper.lambda().eq(SysUserOrder::getUserId,userId);
      List<SysUserOrder> userOrderList = baseMapper.selectList(wrapper);
      List<OrderListDto> list = new ArrayList<>();
        // 2、获取订单详情
        for (SysUserOrder uo: userOrderList
             ) {
            OrderListDto order = baseMapper.getOrderList(uo.getProvinceCode(),uo.getCityCode(),uo.getSubOrderId());
            if (null!=order){
                list.add(order);
            }
        }

        return list;
    }

    @Override
    public int myPact(Long userId) {
        //1、 获取用户订单
        QueryWrapper<SysUserOrder> wrapper = new QueryWrapper<>();
        wrapper.lambda().eq(SysUserOrder::getUserId,userId);
        List<SysUserOrder> userOrderList = baseMapper.selectList(wrapper);
        List<OrderListDto> list = new ArrayList<>();
        // 2、获取订单详情
        for (SysUserOrder uo: userOrderList
        ) {
            OrderListDto order = baseMapper.getOrderList(uo.getProvinceCode(),uo.getCityCode(),uo.getSubOrderId());
            list.add(order);
        }

        return  1;
    }
}
